// mircoApp/idShop/subordinate/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    infoData: {},
    list: [],
    page: 1,
    total_page: 0,
    isLoadMore: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData();
    this.getList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.isLoadMore) {
      this.getMoreData();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  async getData() {
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.project-party.frontend.controllers.index.index")
    })
    if (data.result) {
      if (data.man_type == 0) {
        wx.showModal({
          title: '提示',
          content: '点击确认跳转申请页面',
          showCancel: false,
          complete: (res) => {
            if (res.confirm) {
              wx.navigateTo({
                url: '/mircoApp/idShop/idShop_apply/idShop_apply',
              })
            }
          }
        })
        return
      }
      this.setData({
        infoData: data.data
      })
    } else {
      app.tips(data.msg)
    }
    console.log(data.data)
  },
  async getMoreData() {
    this.data.isLoadMore = false;
    if (this.data.page >= this.data.total_page) return;
    this.setData({
      page: this.data.page + 1
    })
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.project-party.frontend.controllers.index.subMemberList"),
      data: {
        page: this.data.page
      }
    })
    this.data.isLoadMore = true;
    if (data.result) {
      this.setData({
        list: this.data.list.concat(data.data.list.data)
      })
    } else {
      this.setData({
        isLoadMore: false,
        page: this.data.page - 1
      })
    }
  },
  async getList() {
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.project-party.frontend.controllers.index.subMemberList"),
      data: {
        page: this.data.page
      }
    })
    if (data.result) {
      this.setData({
        list: data.data.list.data,
        total_page: data.data.list.pages,
        isLoadMore: true
      })
    } else {
      app.tips(data.msg);
    }
  }
})